<table id="admin_adminInfo_data"></table>
<script>
$(function(){
		$('#admin_adminInfo_data').datagrid({   
	    url:'../adminInfoServlet',
	    queryParams:{op:"getAdminInfo"}, 
	    loadMsg:'努力展开中...',
	    title:'管理员列表',
	    iconCls:'icon-search',
	    fitColumns:true,
	    fit:true,
	    striped:true,
	    pagination:true,
	    rownumbers:true,
	    sortName:'aid',
	    sortOrder:'asc',
	    remoteSort:false,
	    pageNumber:1,
	    pageSize:10,
	   	pageList:[10,20,30,40,50],
	    columns:[[   
	    	{field:'pwd',title:'',checkbox:true,width:100,align:'center'},   
	        {field:'aid',title:'管理员编号',width:100,align:'center',sortable:true},   
	        {field:'aname',title:'管理员姓名',width:100,align:'center'}, 
	        {field:'pwds',title:'管理员密码',width:100,align:'center',formatter:function(value,row,index){
	        	return "******";
	        }},    
	        {field:'statuss',title:'账号状态',width:100,align:'center'}   
	    ]],
	    toolbar: [{
	    	text:'添加',
			iconCls: 'icon-add',
			handler: function(){
				$("#admin_adminInfo_data_add").dialog("open");  //打开对话框
			}
		},'-',{
			text:'删除',
			iconCls: 'icon-remove',
			handler: function(){
				//获取所有被选中的行
				var rows=$('#admin_adminInfo_data').datagrid("getChecked");
				if(rows.length<=0){
					$.messager.alert('温馨提示','请选择您要删除的数据...','info');
				}else{
					$.messager.confirm('信息确认', '您确定要删除选中的记录吗?', function(r){
						if (r){
							var aids="";
							//获取所有选中的数据的id
							for(var i=0;i<rows.length-1;i++){
								aids+=rows[i].aid+",";
							}
							aids+=rows[i].aid;
							//向服务器发送请求
							$.post("../adminInfoServlet?t="+new Date(),{op:"delAdminInfo",aids:aids},function(data){
								data=parseInt($.trim(data));
								if(data>0){
									$.messager.show({title:'温馨提示',msg:'管理员信息删除成功...',timeout:3000,showType:'slide'});
									$('#admin_adminInfo_data').datagrid("reload");
								}else{
									$.messager.alert('失败提示','管理员信息添加失败，请稍后重试...','error');
								}
							});
						}
					});
				}
			}
		},'-',{
	    	text:'修改',
			iconCls: 'icon-edit',
			handler: function(){
				var rows=$('#admin_adminInfo_data').datagrid("getChecked");
				if(rows.length<=0){
					$.messager.alert('温馨提示','请选择要修改的数据...','info');
				}else{
					$("#admin_adminName_update").val(rows[0].aname);
					$("#admin_adminPwd_update").val(rows[0].pwd);
					$("#admin_adminAid_update").val(rows[0].aid);
					$("#admin_adminInfo_data_update").dialog("open");  //打开对话框
				}
			}
		}]
	       
	}); 
}) 

$('#admin_adminInfo_data').datagrid('getPager').pagination({
	beforePageText:'第',
	afterPageText:'页 共{pages}页',
	displayMsg:'当前显示{from}-{to} 条记录 共{total} 条记录'
})

//添加管理员信息
function admin_addInfo(){
	var aname=$.trim( $("#admin_adminName").val() );
	var pwd=$.trim( $("#admin_adminPwd").val() );
	
	if(aname!="" && pwd!=""){
		$.post("../adminInfoServlet?t="+new Date(),{op:"addAdminInfo",aname:aname,pwd:pwd},function(data){
			data=parseInt($.trim(data));
			if(data>0){
				$.messager.show({title:'成功提示',msg:'管理员信息添加成功...',timeout:3000,showType:'slide'});
				$("#admin_adminName").val("");
				$("#admin_adminPwd").val("");
				$("#admin_adminInfo_data_add").dialog("close");  //关闭对话框
				$('#admin_adminInfo_data').datagrid("reload");
			}else{
				$.messager.alert('失败提示','管理员信息添加失败，请稍后重试...','error');
			}
		});
	}else{
		$.messager.show({
			title:'温馨提示',
			msg:'您输入的信息不完整，请确认后再提交...',
			timeout:3000,
			showType:'slide'
		});
	}
}

//修改管理员信息
function admin_updateInfo(){
	var aname=$.trim( $("#admin_adminName_update").val() );
	var pwd=$.trim( $("#admin_adminPwd_update").val() );
	var aid=$.trim( $("#admin_adminAid_update").val() );
	
	$.post("../adminInfoServlet?t="+new Date(),{op:"updateAdminInfo",aname:aname,pwd:pwd,aid:aid},function(data){
		data=parseInt($.trim(data));
		if(data>0){
			$.messager.show({title:'成功提示',msg:'管理员信息修改成功...',timeout:3000,showType:'slide'});
			$("#admin_adminName_update").val("");
			$("#admin_adminPwd_update").val("");
			$("#admin_adminAid_update").val("");
			$("#admin_adminInfo_data_update").dialog("close");
			$('#admin_adminInfo_data').datagrid("reload");
		}else{
			$.messager.alert('失败提示','管理员信息修改失败，请稍后重试...','error');
		}
	});
}
</script>

<div id="admin_adminInfo_data_add" class="easyui-dialog" title="添加管理员信息" style="width:400px;height:200px;"data-options="iconCls:'icon-add',resizable:true,modal:true,closed:true">  
   <br /><br />
   <center>
   		<label for="admin_adminName">管理员姓名：</label><input type="text" id="admin_adminName" class="easyui-validatebox" 
   				data-options="required:true,missingMessage:'请输入管理员账号'"/><br /><br />
   		<label for="admin_adminPwd">管理员密码：</label><input type="password" id="admin_adminPwd" class="easyui-validatebox" 
   				data-options="required:true,missingMessage:'请输入管理员密码',validType:'length[6,12]',invaildMessage:'密码长度不得小于6位'" /><br /><br />
   		<input type="button" onclick="admin_addInfo()" value="添加">
   </center>   
</div>  

<div id="admin_adminInfo_data_update" class="easyui-dialog" title="修改管理员信息" style="width:400px;height:200px;"data-options="iconCls:'icon-edit',resizable:true,modal:true,closed:true">  
   <br /><br />
   <input type="hidden" id="admin_adminAid_update">
   <center>
   		<label for="admin_adminName_update">管理员姓名：</label><input type="text" id="admin_adminName_update" /><br /><br />
   		<label for="admin_adminPwd_update">管理员密码：</label><input type="password" id="admin_adminPwd_update" /><br /><br />
   		<input type="button" onclick="admin_updateInfo()" value="修改">
   </center>   
</div>  




